package com.dxb.yomall.search.controller;

import com.dxb.yomall.search.service.MallSearchService;
import com.dxb.yomall.search.vo.SearchParamVO;
import com.dxb.yomall.search.vo.SearchResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * 商品检索 {@link SearchController}
 *
 * @author Kevin
 * @email: 178676392@qq.com
 */
@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;

    /**
     * 商品检索
     * @param searchParamVO 检索条件
     * @param model 存放检索结果
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParamVO searchParamVO, Model model, HttpServletRequest request) {
        searchParamVO.setQueryString(request.getQueryString());
        SearchResponseVO searchResponseVO = mallSearchService.search(searchParamVO);
        model.addAttribute("searchResponseVO", searchResponseVO);
        return "list";
    }
}